package testaux;

import java.util.Arrays;
import java.util.List;

public class Cons<T> {
    public final T head;
    public final Cons<T> tail;

    public Cons(T head) {
        this.head = head;
        this.tail = null;
    }

    public Cons(T head, Cons<T> tail) {
        this.head = head;
        this.tail = tail;
    }

    public List<T> toList() {
        if (tail == null)
            return Arrays.asList(head);
        List<T> t = tail.toList();
        t.add(0, head);
        return t;
    }
}
